package com.rivulet.dawn.web.controller.archive;

import com.rivulet.dawn.api.request.AllDeleteRequest;
import com.rivulet.dawn.api.request.archive.PersonRecordQueryRequest;
import com.rivulet.dawn.api.request.archive.PersonRecordSaveRequest;
import com.rivulet.dawn.api.request.archive.PersonRecordUpdateRequest;
import com.rivulet.dawn.api.response.archive.PersonRecordDetailResponse;
import com.rivulet.dawn.api.response.archive.PersonRecordSearchResponse;
import com.rivulet.dawn.api.tools.Page;
import com.rivulet.dawn.api.tools.ResultFul;
import com.rivulet.dawn.service.service.archive.PersonRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: xjc
 * @date: 2022/8/16 16:32
 **/
@Api(value = "人物志管理",tags = "人物档案管理")
@RestController
@RequestMapping("archive/person/")
public class PersonRecordController {
    private final PersonRecordService personRecordService;

    public PersonRecordController(PersonRecordService personRecordService) {
        this.personRecordService = personRecordService;
    }

    @ApiOperation(value = "人物新增")
    @PostMapping("create")
    public ResultFul<Integer> create(@RequestBody PersonRecordSaveRequest request){
        return ResultFul.OK(personRecordService.create(request));
    }

    @ApiOperation(value = "人物删除")
    @PostMapping("delete")
    public ResultFul<Object> delete(@RequestBody AllDeleteRequest request){
        personRecordService.delete(request);
        return ResultFul.OK();
    }

    @ApiOperation(value = "人物修改")
    @PostMapping("update")
    public ResultFul<Integer> update(@RequestBody PersonRecordUpdateRequest request){
        return ResultFul.OK(personRecordService.update(request));
    }

    @ApiOperation(value = "人物查询")
    @PostMapping("search")
    public ResultFul<Page<PersonRecordSearchResponse>> search(@RequestBody PersonRecordQueryRequest request){
        return ResultFul.OK(personRecordService.search(request));
    }

    @ApiOperation(value = "人物详情")
    @PostMapping("detail")
    public ResultFul<PersonRecordDetailResponse> detail(Long id){
        return ResultFul.OK(personRecordService.detail(id));
    }
}
